(function($, document, window) {
  'use strict';

 var ns = jfJQMAmobeeAds;

 function onClickOpenChildbrowser(e) {
   var $this = $(this);
   var url = $this.attr('href');
   if (!url.match(/^http/)) {
     return;
   }

   e.stopPropagation();
   e.preventDefault();

   window.plugins.childBrowser.showWebPage(url);

   return false;
 }
 
 if (window.PhoneGap) {

   document.addEventListener('deviceready', function() {

     if (window.ChildBrowser && window.ChildBrowser.install) {
       window.ChildBrowser.install(); //on iOS the ChildBrowser Plugin does not install itself automatically
     }

     if (window.plugins && window.plugins.childBrowser) {
       $('.jfJQMAmobeeAd a[href]').live('click', onClickOpenChildbrowser);
     }
    
    //hide/show native tabbar when interstitial is shown/hidden
    if (window.plugins && window.plugins.nativeControls) {
      var nsShowInterstitial = ns.showInterstitial;
      ns.showInterstitial = function($interstitial) {
        window.plugins.nativeControls.hideTabBar();
        var result = nsShowInterstitial($interstitial);        
        return result;
      };
      
      var nsHideInterstitial = ns.hideInterstitial;
      ns.hideInterstitial = function($interstitial, timeout, immediately) {
        var result = nsHideInterstitial($interstitial, timeout, immediately);        
        window.plugins.nativeControls.showTabBar();
        return result;
      };
    }

     
   });
 }

})(window.jQuery, document, window);